package com.biz.primus.app.rest.controller.order;

import com.biz.primus.app.rest.controller.base.RestBaseController;
import com.biz.primus.app.rest.feign.order.OrderFeignClient;
import com.biz.primus.base.support.rest.vo.JsonResult;
import com.biz.primus.base.global.GlobalParams;
import com.biz.primus.model.order.vo.request.OrderCodeVO;
import com.biz.primus.model.order.vo.request.OrderSummaryRequestVO;
import com.biz.primus.model.order.vo.response.OrderSummaryResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yanweijin
 * @date 2017/11/3
 * @modify Tiger 2017/11/16
 */
@RestController
@RequestMapping("order")
@Api("前台订单相关接口文档")
public class OrderController extends RestBaseController {
    @Autowired
    private OrderFeignClient orderService;

    @ApiOperation(value = "订单结算", notes = "计算当前订单金额", response = OrderSummaryResponseVO.class)
    @PostMapping("settlement")
    public JsonResult settleOrder(GlobalParams gp,
                                  @RequestBody OrderSummaryRequestVO requestVO) {
        super.buildRequest(gp, requestVO);
        return new JsonResult(orderService.settleOrder(requestVO));
    }

    @ApiOperation("创建订单")
    @PostMapping("create")
    public JsonResult createOrder(GlobalParams gp,
                                  @RequestBody OrderSummaryRequestVO requestVO) {
        super.buildRequest(gp, requestVO);
        return new JsonResult(orderService.createOrder(requestVO));
    }

    @ApiOperation(value = "获取订单", notes = "根据订单编码获取订单")
    @PostMapping("queryByOrderCode")
    public JsonResult getByOrderCode(GlobalParams gp,
                                     @RequestBody OrderCodeVO orderCodeVO) {
        super.buildRequest(gp, orderCodeVO);
        return new JsonResult(orderService.getByOrderCode(orderCodeVO));
    }

    @ApiOperation(value = "取消订单", notes = "取消指定订单编码的订单")
    @PostMapping("cancelOrder")
    public void cancelOrder(GlobalParams gp,
                            @RequestBody OrderCodeVO orderCodeVO) {
        super.buildRequest(gp, orderCodeVO);
        orderService.cancelOrder(orderCodeVO);
    }

}
